package com.sgcc.pda.mdrh.h5.task;

import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;

import com.sgcc.pda.common.aidl.CommonCallback;
import com.sgcc.pda.common.aidl.CommonParams;
import com.sgcc.pda.common.aidl.CommonResults;
import com.sgcc.pda.h5.db.DBH5BinderUtil;
import com.sgcc.pda.mdrh.h5.library.CallBackFunction;

/**
 * author : think
 * e-mail : xxx@xx
 * time   : 2019/08/27
 * desc   : 数据库操作,开启异步任务
 * version: 1.0
 */
public class DBH5Task extends AsyncTask<Object, String, CommonResults> {

    private CallBackFunction callBackFunction;

    public DBH5Task(CallBackFunction callBackFunction) {
        this.callBackFunction = callBackFunction;
    }

    @Override
    protected CommonResults doInBackground(Object... objects) {
        return DBH5BinderUtil.getInstance().execute((CommonParams) objects[0], new CommonCallback() {
            @Override
            public void callback(final CommonResults commonResults) {
                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    @Override
                    public void run() {
                        //do nothing
                    }
                });
            }
        });
    }

    @Override
    protected void onPostExecute(CommonResults commonResults) {
        super.onPostExecute(commonResults);
        callBackFunction.onCallBack(commonResults.toJSON());
    }
}
